import React from 'react';

const contextState = {
    leftList: null,
    rightList: null,
    currentPosition: null,
    currentTemplate: null,
    currentItem: null,
    getOppositeTemplate() {
        const { currentPosition, currentTemplate } = this;

        if (!currentPosition || !currentTemplate) {
            return null;
        }

        const oppositeList = (currentPosition === 'left' ? this.rightList : this.leftList) || [];

        return oppositeList.find(template => template.month === this.currentTemplate.month);
    },
    getOppositeItem() {
        const oppositeTemplate = this.getOppositeTemplate() || {};
        const usedAddSalaryItems = oppositeTemplate.usedAddSalaryItems ?? [];
        const usedLessSalaryItems = oppositeTemplate.usedLessSalaryItems ?? [];
        const items = [...usedAddSalaryItems, ...usedLessSalaryItems];

        return items.find(item => item.id === this.currentItem.id);
    }
};

const context = {
    contextState,
    setContextState() {}
};

export default React.createContext(context);
export { contextState as contextValue };
